package com.qingcheng.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 岳剑飞
 * @Company http://www.ithiema.com
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    /**
     * 获取登录的用户名
     *
     * @return
     */
    @RequestMapping("/username")
    public Map username() {

        String name = SecurityContextHolder.getContext().getAuthentication().getName();  //获取登录人账号
        if ("anonymousUser".equals(name)) {  //登录人账号不能是默认虚拟账号
            name = "";
        }

        System.out.println(name);
        Map map = new HashMap();
        map.put("username", name);
        return map;
    }

}
